import api from '@/utils/api'

export function createDataSourceApi(data) {
  return api({
    url: '/dataSource',
    method: 'post',
    data
  })
}

export function updateDataSourceApi(data) {
  return api({
    url: '/dataSource',
    method: 'put',
    data
  })
}

export function deleteDataSourceApi(params) {
  return api({
    url: '/dataSource/' + params,
    method: 'delete'
  })
}

export function dataSourceListApi(params) {
  return api({
    url: '/dataSource',
    method: 'get',
    params
  })
}


//---------------------------------------------------------

export function testConnectApi(data) {
  return api({
    url: '/testConnect',
    method: 'post',
    data
  })
}

export function getConnectApi(data) {
  return api({
    url: '/getConnect',
    method: 'post',
    data
  })
}

export function getFieldByTableNameApi(data) {
  return api({
    url: '/getFieldByTableName',
    method: 'post',
    data
  })
}

export function getCountByTableNameApi(data) {
  return api({
    url: '/getCountByTableName',
    method: 'post',
    data
  })
}


// ---------------------------------------------------------

export function generateDataApi(data) {
  return api({
    url: '/dataGenerate/generateData',
    method: 'post',
    data
  })
}

export function exportExcelApi(data) {
  return api({
    url: '/dataGenerate/exportExcel',
    method: 'post',
    data,
    responseType: 'blob'  // 表明返回服务器返回的数据类型，要加在请求头里面，否则识别不了文件流
  })
}

export function testFakerApi(data) {
  return api({
    url: '/dataGenerate/test',
    method: 'post',
    data
  })
}


// ---------------------------------------------------------
export function saveMappingApi(data) {
  return api({
    url: '/addFieldMapping',
    method: 'post',
    data
  })
}

export function fieldMappingListApi(data) {
  return api({
    url: '/getFieldMappingList',
    method: 'post',
    data
  })
}

export function deleteFieldMappingApi(params) {
  return api({
    url: '/deleteFieldMapping/' + params,
    method: 'delete',
  })
}


// ---------------------------------------------------------
export function ruleConfigReApi(data) {
  return api({
    url: '/ruleConfig/reList',
    method: 'post',
    data
  })
}


export function createReApi(data) {
  return api({
    url: '/ruleConfig/re',
    method: 'post',
    data
  })
}

export function updateReApi(data) {
  return api({
    url: '/ruleConfig/re',
    method: 'put',
    data
  })
}

export function deleteReApi(params) {
  return api({
    url: '/ruleConfig/re/' + params,
    method: 'delete'
  })
}

export function ruleConfigFakerApi() {
  return api({
    url: '/ruleConfig/faker',
    method: 'get'
  })
}
